<template>
  <div class="footer-container" v-show="total">
    <div class="footer-container-left">
      <input type="checkbox" v-model="isAll">
      <span>已完成:{{ completed }}</span>/<span>合计：{{ total }}</span>
    </div>
    <div class="footer-container-right">
      <button @click="handleClearAll">清除所有已完成</button>
    </div>
  </div>
</template>

<script>

export default {
  name: "MyFooter",
  props: ['todos'],
  computed: {
    total() {
      return this.todos.length
    },
    completed() {
      return this.todos.filter((todo) => {
        return todo.done
      }).length
    },
    isAll: {
      get() {
        return this.completed === this.total && this.total > 0
      },
      set(value) {
        this.$emit('checkAll',value)
      }
    }
  },
  methods: {
    handleClearAll(){
      this.$emit('clearAll')
    }
  },
}
</script>

<style scoped>
.footer-container {
  width: 400px;
}

.footer-container-left {
  float: left;
  margin-left: 10px;
  font-weight: bolder;
}

.footer-container-right {
  float: right;
  margin-right: 10px;
}

input {
  margin-right: 10px;
}
</style>